package com.yc.ioc.test.bean3.Factory;

import com.yc.ioc.test.bean3.other.Banana;
import com.yc.ioc.test.bean3.other.Fruit;
import com.yc.ioc.test.bean3.other.Grape;
import org.springframework.beans.factory.FactoryBean;

import java.util.Random;

public class FruitFactoryBean implements FactoryBean<Fruit> {

    @Override
    public Fruit getObject() throws Exception {
        Random r=new Random();
        if (r.nextInt(2)==1){
            return new Grape();
        }else {
            return new Banana();
        }
    }

    @Override
    public Class<?> getObjectType() {
        return Fruit.class;
    }
}
